package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.commons.utils.ResStatus;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.dto.doctordto;
import com.woniuxy.model.Doctor;
import com.woniuxy.mapper.DoctorMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.service.IDoctorService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 医生表 服务实现类
 * </p>
 *
 * @author litongmiao
 * @since 2022-06-08
 */
@Service
public class DoctorServiceImpl extends ServiceImpl<DoctorMapper, Doctor> implements IDoctorService {

    @Resource
    private DoctorMapper doctorMapper;
    @Override
    public ResponseResult<Doctor> findAllByPage(long current, long limit) {
        Page<Doctor> page = new Page<>(current, limit);
        Page<Doctor> doctorPage = doctorMapper.selectPage(page, null);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setStatus(ResStatus.SUCCESS);
        responseResult.setMsg("查询成功");
        responseResult.setData(doctorPage);
        System.out.println(doctorPage.toString());
        responseResult.setCode(200);
        return responseResult;

    }

    @Override
    public ResponseResult findDoctorByPage(long current, long limit,int active, doctordto doctordto) {

        if (doctordto!=null){
            QueryWrapper<Doctor> wrapper=new QueryWrapper<>();
            if (!StringUtils.isEmpty(active)) {
                if (active == -1){

                }else {
                    wrapper.eq("qualification_status",active);
                }
            }
            if (!StringUtils.isEmpty(doctordto.getName())){
                wrapper.like("name",doctordto.getName());
            }
            if (!StringUtils.isEmpty(doctordto.getDepartment())){
                wrapper.eq("department",doctordto.getDepartment());
            }
            if (!StringUtils.isEmpty(doctordto.getProfessionalTitle())){
                wrapper.eq("professional_title",doctordto.getProfessionalTitle());
            }
            Page<Doctor> page=new Page<>(current,limit);
            Page<Doctor> doctorPage = doctorMapper.selectPage(page, wrapper);
            ResponseResult responseResult=new ResponseResult();
            responseResult.setStatus(ResStatus.SUCCESS);
            responseResult.setMsg("查询成功");
            responseResult.setData(doctorPage);
            responseResult.setCode(200);
            return responseResult;
        }else {
            QueryWrapper<Doctor> wrapper=new QueryWrapper<>();
            if (!StringUtils.isEmpty(active)) {
                if (active == -1){

                }else {
                    wrapper.eq("qualification_status",active);
                }

            }
            Page<Doctor> page=new Page<>(current,limit);
            Page<Doctor> doctorPage = doctorMapper.selectPage(page, wrapper);
            ResponseResult responseResult=new ResponseResult();
            responseResult.setStatus(ResStatus.SUCCESS);
            responseResult.setMsg("查询成功");
            responseResult.setData(doctorPage);
            responseResult.setCode(200);
            return responseResult;
        }



        //构建条件



        //调用方法实现分页


    }

    @Override
    public ResponseResult findDoctorByName(String name) {
        QueryWrapper<Doctor> wrapper=new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)){
            wrapper.like("name",name);
        }
        List<Doctor> doctorList=doctorMapper.selectList(wrapper);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setStatus(ResStatus.SUCCESS);
        responseResult.setMsg("查询成功");
        responseResult.setData(doctorList);
        responseResult.setCode(200);
        return responseResult;
    }

    @Override
    public ResponseResult findDoctorSH(long current, long limit) {
        QueryWrapper<Doctor> wrapper=new QueryWrapper<>();
        Page<Doctor> page=new Page<>(current,limit);
        wrapper.eq("qualification_status",1);

        Page<Doctor> doctorPage = doctorMapper.selectPage(page, wrapper);

        ResponseResult responseResult=new ResponseResult();
        responseResult.setStatus(ResStatus.SUCCESS);
        responseResult.setMsg("查询成功");
        responseResult.setData(doctorPage);
        responseResult.setCode(200);
        return responseResult;
    }

    @Override
    public ResponseResult findDoctorWSH(long current, long limit) {
        QueryWrapper<Doctor> wrapper=new QueryWrapper<>();
        Page<Doctor> page=new Page<>(current,limit);
        wrapper.eq("qualification_status",0);

        Page<Doctor> doctorPage = doctorMapper.selectPage(page, wrapper);

        ResponseResult responseResult=new ResponseResult();
        responseResult.setStatus(ResStatus.SUCCESS);
        responseResult.setMsg("查询成功");
        responseResult.setData(doctorPage);
        responseResult.setCode(200);
        return responseResult;
    }

    @Override
    public ResponseResult deleteDoctor(int id) {
        QueryWrapper<Doctor> wrapper=new QueryWrapper<>();
        int i = doctorMapper.deleteById(id);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setStatus(ResStatus.SUCCESS);
        responseResult.setMsg("删除成功");
        responseResult.setData(i);
        responseResult.setCode(200);
        return responseResult;
    }

    @Override
    public ResponseResult updateFWByid(int id,int status) {
        QueryWrapper<Doctor> wrapper=new QueryWrapper<>();
        doctorMapper.setFWStatus(id,status);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setStatus(ResStatus.SUCCESS);
        responseResult.setMsg("更改成功");
        responseResult.setData(null);
        responseResult.setCode(200);
        return responseResult;

    }

    @Override
    public ResponseResult updateZGByid(int id, int status) {
        QueryWrapper<Doctor> wrapper=new QueryWrapper<>();
        doctorMapper.setZGStatus(id,status);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setStatus(ResStatus.SUCCESS);
        responseResult.setMsg("更改成功");
        responseResult.setData(null);
        responseResult.setCode(200);
        return responseResult;
    }

    @Override
    public ResponseResult findDoctorById(long id) {
        Doctor doctor = doctorMapper.selectById(id);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setStatus(ResStatus.SUCCESS);
        responseResult.setMsg("查询成功");
        responseResult.setData(doctor);
        responseResult.setCode(200);
        return responseResult;
    }


}
